﻿using System;

namespace Netbits.Common.Conditions
{
	/// <summary>
	/// String extensions for validator class
	/// </summary>
	public static partial class ValidatorExtensions
	{
		/// <summary>
		/// Checks if the given value is empty
		/// </summary>
		/// <param name="Validator_">The strongly typed validator</param>
		/// <returns>The Validator if the Value_ is empty, otherwise ConditionException is thrown</returns>
		/// <exception cref="ConditionException">Thrown if the given value is not empty</exception>
		public static Validator<string> IsEmpty( this Validator<string> Validator_ )
		{
			if( string.IsNullOrEmpty( Validator_.__Value ) )
				return Validator_;
			throw new ConditionException( "{0} is not empty", Validator_.GetStringOfValue() );
		}

		/// <summary>
		/// Checks if the given value is not empty
		/// </summary>
		/// <param name="Validator_">The strongly typed validator</param>
		/// <returns>The Validator if the value is empty; otherwise ConditionException is thrown</returns>
		/// <exception cref="ConditionException">Thrown if the given value is empty</exception>
		public static Validator<string> IsNotEmpty( this Validator<string> Validator_ )
		{
			if( !string.IsNullOrEmpty( Validator_.__Value ) )
				return Validator_;
			throw new ConditionException( "{0} is empty", Validator_.GetStringOfValue() );
		}
	}
}
